package com.enjoyor.soa.traffic.server.tsms.dubbo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tsms.TaskInfoDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboTaskInfoService;
import com.enjoyor.soa.traffic.core.tsms.domain.TaskDetailInfo;
import com.enjoyor.soa.traffic.core.tsms.domain.TaskInfo;
import com.enjoyor.soa.traffic.core.tsms.service.ITaskInfoService;
import com.enjoyor.soa.traffic.server.tsms.helper.EntityChangeHelper;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboTaskInfoService implements IDubboTaskInfoService {

    @Autowired
    private ITaskInfoService taskInfoService;

    @Override
    public ResultPojo selectTaskInfoById(String taskId) {
    	TaskInfo taskInfo = taskInfoService.selectTaskInfoById(taskId);
        return new ResultPojo(EntityChangeHelper.taskPojoToDto(taskInfo));
    }

	@Override
	public ResultPojo selectTaskInfoList(String taskId, String taskName, String schemeId, String taskRankId,
			String taskTypeId, String taskBeginTime, String taskEndTime, String startPlace, String targetPlace) {
		List<TaskInfo> taskInfoList = taskInfoService.selectTaskInfoList(taskId, taskName, schemeId, taskRankId,
				taskTypeId, taskBeginTime, taskEndTime, startPlace, targetPlace);
		return new ResultPojo(EntityChangeHelper.taskPojoToDtoList(taskInfoList));
	}

	@Override
	public ResultPojo selectTaskInfoPage(Page page, String taskId, String taskName, String schemeId, String taskRankId,
			String taskTypeId, String taskBeginTime, String taskEndTime, String startPlace, String targetPlace) {
		return new ResultPojo(taskInfoService.selectTaskInfoPage(page, taskId, taskName, schemeId, taskRankId,
				taskTypeId, taskBeginTime, taskEndTime, startPlace, targetPlace));
	}

    /**
	 * 根据执行任务编号查询执行任务信息
	 */
    public ResultPojo selectExecuteTaskInfoById(String executeTaskId){
    	TaskDetailInfo taskDetailInfo = taskInfoService.selectExecuteTaskInfoById(executeTaskId);
        return new ResultPojo(EntityChangeHelper.taskDetailPojoToDto(taskDetailInfo));
    }
    
	/**
	 * 查询执行任务列表信息
	 */
	public ResultPojo selectExecuteTaskBaseInfoList(String executeTaskId, String taskId, String taskName,
			String schemeId, String taskRankId, String taskTypeId, String beforeLicensePlate, String executeDate,
			String beginTime, String endTime, String startPlace, String targetPlace, String executeStatusId,
			String isWaitExecute) {
		List<TaskDetailInfo> taskDetailInfoList = taskInfoService.selectExecuteTaskBaseInfoList(executeTaskId, taskId,
				taskName, schemeId, taskRankId, taskTypeId, beforeLicensePlate, executeDate, beginTime, endTime,
				startPlace, targetPlace, executeStatusId, isWaitExecute);
		return new ResultPojo(EntityChangeHelper.taskDetailPojoToDtoList(taskDetailInfoList));
	}

	/**
	 * 查询执行任务详细列表信息
	 */
	public ResultPojo selectExecuteTaskDetailInfoList(String executeTaskId, String taskId, String taskName,
			String schemeId, String taskRankId, String taskTypeId, String beforeLicensePlate, String executeDate,
			String beginTime, String endTime, String startPlace, String targetPlace, String executeStatusId,
			String isWaitExecute) {
		List<TaskDetailInfo> taskDetailInfoList = taskInfoService.selectExecuteTaskDetailInfoList(executeTaskId, taskId,
				taskName, schemeId, taskRankId, taskTypeId, beforeLicensePlate, executeDate, beginTime, endTime,
				startPlace, targetPlace, executeStatusId, isWaitExecute);
		return new ResultPojo(EntityChangeHelper.taskDetailPojoToDtoList(taskDetailInfoList));
	}

	/**
	 * 查询执行任务分页信息
	 * @param page
	 */
	public ResultPojo selectExecuteTaskInfoPage(Page page, String executeTaskId, String taskId, String taskName,
			String schemeId, String taskRankId, String taskTypeId, String beforeLicensePlate, String executeDate,
			String beginTime, String endTime, String startPlace, String targetPlace, String executeStatusId,
			String isWaitExecute) {
		return new ResultPojo(taskInfoService.selectExecuteTaskInfoPage(page, executeTaskId, taskId, taskName, schemeId,
				taskRankId, taskTypeId, beforeLicensePlate, executeDate, beginTime, endTime, startPlace, targetPlace,
				executeStatusId, isWaitExecute));
	}
    
    @Override
    public ResultPojo insertTaskInfo(TaskInfoDto taskInfoDto, String userName) {
    	ResultPojo resultPojo = new ResultPojo();
    	String taskId = taskInfoService.insertTaskInfo(EntityChangeHelper.taskDtoToPojo(taskInfoDto), userName);
    	if( !"false".equals(taskId) ) {
			resultPojo = new ResultPojo(taskId);
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "任务参数错误！");
		}
		return resultPojo;
    }

    @Override
    public ResultPojo editTaskInfo(TaskInfoDto taskInfoDto, String userName) {
    	int resultNum = taskInfoService.editTaskInfo(EntityChangeHelper.taskDtoToPojo(taskInfoDto), userName);
        return new ResultPojo(resultNum);
    }
    
    @Override
    public ResultPojo editTaskBaseInfo(TaskInfoDto taskInfoDto, String userName) {
    	int resultNum = taskInfoService.editTaskBaseInfo(EntityChangeHelper.taskDtoToPojo(taskInfoDto), userName);
        return new ResultPojo(resultNum);
    }

    @Override
    public ResultPojo deleteTaskInfo(String taskId, String userName) {
    	int resultNum = taskInfoService.deleteTaskInfo(taskId, userName);
        return new ResultPojo(resultNum);
    }
    
    @Override
    public ResultPojo insertFastTaskInfo(TaskInfoDto taskInfoDto, String userName) {
    	ResultPojo resultPojo = new ResultPojo();
    	String taskId = taskInfoService.insertFastTaskInfo(EntityChangeHelper.taskDtoToPojo(taskInfoDto), userName);
    	if( !"false".equals(taskId) ) {
			resultPojo = new ResultPojo(taskId);
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "快速特勤参数错误！");
		}
		return resultPojo;
    }

    @Override
    public ResultPojo editFastTaskInfo(TaskInfoDto taskInfoDto, String userName) {
    	int resultNum = taskInfoService.editFastTaskInfo(EntityChangeHelper.taskDtoToPojo(taskInfoDto), userName);
        return new ResultPojo(resultNum);
    }

    @Override
    public ResultPojo deleteFastTaskInfo(String taskId, String userName) {
    	int resultNum = taskInfoService.deleteFastTaskInfo(taskId, userName);
        return new ResultPojo(resultNum);
    }
    
	@Override
	public ResultPojo getTaskByTimeAndSchemeId(String schemeId, String date) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		List list = taskInfoService.getTaskListByDateAndSchemeId(schemeId, date);
		resultPojo.setResultList(list);
		return resultPojo;
	}

}
